<#escape x as x?html>
<SCRIPT type="text/javascript">
<!--
	var menuTreesetting = {
		callback: {
			onClick:MenuzTreeOnClick
		},
		data : {
			simpleData : {
				enable : true,
				idKey : "id",
				pIdKey : "pid",
				rootPId : "null"
			}
		}
	};

	$(document).ready(function() {
		
		jQuery.post("${ctx}/system/menu/list/json",
				function(_json) {
					if (_json.status == "success") {
						$.fn.zTree.init($("#menuListTree"), menuTreesetting,_json.data);
						
						var zTree =$.fn.zTree.getZTreeObj("menuListTree");
					    	//zTree.expandAll(true);
						
					} else {
						myalert(_json.message);
					}
				});
		
	});
	
	function MenuzTreeOnClick(event, treeId, treeNode) {
	    showdata(treeNode);
	};
	
	function showdata(result) {
		$("#updateForm select ").each(function() {
			$(this).find('option:first').attr('selected', 'selected');
		});
		for (var s in result) {
			set_val(s, result[s]);
		}
		
		var _pid=result["pid"];
		if((!_pid)||_pid==null||_pid=="null"||_pid==""){
			jQuery("#pid").val("");
		}else{
			jQuery("#pid").val(_pid);
		}
		
		
		var _pNode= result.getParentNode();
		if(_pNode){
			jQuery("#pname").val(_pNode["name"]);
		}else{
			jQuery("#pname").val("");
		}
		
	}
	
	
	function deleteMenu(){
		var id=jQuery("#id").val();
		if(!id||id==""){
			myalert("请选择你要删除的记录");
			return;
		}else{
			var _url="${ctx}/system/menu/delete?id="+id;
			var listurl="${ctx}/system/menu/list";
			mydelete(_url,listurl);
		}
	}
	
	
	//-->
	</SCRIPT>

<div class="operate panel panel-default" style="height:65px;">
	<div class="panel-body">
		<div class="pull-right">
			 <@shiro.hasPermission
			name="/system/menu/update" >
			<button onclick="commonSaveForm('updateForm','${ctx}/system/menu/list');"
				class="btn  btn-sm  btn-primary">
				添加
			</button>
				<button onclick="commonUpdateForm('updateForm','${ctx}/system/menu/list');"
				class="btn  btn-sm  btn-primary">
				修改
			</button>
			
			</@shiro.hasPermission>
			 <@shiro.hasPermission name="/system/menu/delete" >
			<button onclick="deleteMenu();" class="btn btn-sm btn-danger">
				 删除
			</button>
			</@shiro.hasPermission>
		</div>
	</div>
</div>
<!-- 功能操作区域结束 -->
<!-- 列表显示区域  -->
<div class="row">
	<div class="col-sm-4 sub_left_menu">
		<div class="well">
				<ul id="menuListTree" class="ztree"></ul>
		</div>
	</div>
	<div class="col-sm-8 sub_content">
		<form id="updateForm" name="updateForm"  action="${ctx}/system/menu/update"   method="post" class="well form-horizontal clearfix">
			<input type="hidden" name="id" id="id">
			<div class="form-group col-xs-12">
				<label class="col-sm-4 control-label" for="name">名称*：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" id="name" name="name" check="require" msg="请输入名称">
				</div>
			</div>

			<div class="form-group col-xs-12">
				<label class="col-sm-4 control-label" for="url">地址：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" id="pageurl" name="pageurl">
				</div>
			</div>

			<div class="form-group col-xs-12">
				<label class="col-sm-4 control-label" for="pid">父节点：</label>
				<div class="col-sm-8">
					<div class="input-group">
						<input name="pname" class="form-control val" id="pname" type="text"  readonly="readonly"/>
						<input name="pid"  id="pid" type="hidden" msg="请选择父节点" check="require"  />
						<span class="input-group-btn">
								<a data-trigger="modal" href="${ctx}/system/menu/tree" data-title="选择父节点" class="btn btn-sm btn-primary">
															<i class="fa fa-search"></i>
								</a>
						 </span>
					</div>
				</div>
			</div>
			
			<div class="form-group col-xs-12">
				<label class="col-sm-4 control-label" for="type">资源类型：</label>
				<div class="col-sm-8">
					<select   name="type" id="type" class="form-control">
						<option  value="0">按钮资源</option>
						<option value="1">导航菜单</option>
					</select>
				</div>
			</div>
			
			
			<div class="form-group col-xs-12">
				<label class="col-sm-4 control-label" for="icon">图标：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" id="icon" name="icon" >
				</div>
			</div>
			
			
			<div class="form-group col-xs-12">
				<label class="col-sm-4 control-label" for="sort">排序：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" id="sort" name="sort" >
				</div>
			</div>

			<div class="form-group col-xs-12">
				<label class="col-sm-4 control-label" for="state">是否可用*：</label>
				<div class="col-sm-8">
					<select   name="state" id="state" class="form-control">
						<option  value="是">是</option>
						<option value="否">否</option>
					</select>
				</div>
			</div>

			<div class="form-group col-xs-12">
				<label class="col-sm-4 control-label" for="description" >备注：</label>
				<div class="col-sm-8" >
					<textarea class="form-control" name="description"  id="description" rows="5" class="col-xs-12" ></textarea>
				</div>
			</div>
		</form>
	</div>
</div>
</#escape>